package com.noahsloan.nutils.streams;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;

/**
 * @see #OutputStreamSeries(Iterator)
 */
public class OutputStreamSeries extends FilterOutputStream {

    private Iterator<OutputStream> it;

    /**
     * Iterates over the OutputStreams, deferring all operations to the current
     * stream. Calling {@link #close()} advances to the next stream.
     * 
     * @param it
     */
    public OutputStreamSeries(Iterator<OutputStream> it) {
        super(it.next());
        this.it = it;
    }

    @Override
    /**
     * Advances the underlying stream to the next stream.
     */
    public void close() throws IOException {
        super.close();
        out = it.next();
    }
}
